home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-04-29 | 13.4 KB | 499 lines |
- /**
- *
- * You can add code anywhere in this file - except in the areas that are
- * written by the editor. You should not change the relative ordering of
- * the code.
- *
- * You can remove this comment block or replace it with another.
- *
- * @see
- * @version
- * @author
- */
-
- import java.awt.*;
- import java.awt.event.*;
- import java.beans.*;
- import java.io.*;
- import java.net.*;
- import java.util.*;
- import com.supercede.forms.*;
-
- public class MainForm extends SuperCedeFrame implements Serializable, AdventureConstants
- {
-
- void mainFormPreInit()
- {
- // You can add code anywhere in this method.
- // This method is called PRIOR to form initialization.
- // NOTE: The form has NOT been initialized yet. Do not modify the form itself in this method.
- }
-
- void mainFormPostInit()
- {
- // You can add code anywhere in this method.
- // This method is called AFTER form initialization.
-
- // Here I create a File Menu bar and items
-
- // create MenuBar
- MenuBar menubar = new MenuBar();
- // add File menu
- Menu fileMenu = new Menu ("File");
- // add Help menu
- Menu helpMenu = new Menu ("Help");
- // declare MenuItems
- MenuItem exitItem;
- MenuItem loadItem;
- MenuItem saveItem;
- MenuItem aboutItem;
- // add MenuItems to File Menu
- fileMenu.add(loadItem = new MenuItem("Load"));
- fileMenu.add(saveItem = new MenuItem("Save"));
- fileMenu.addSeparator();
- fileMenu.add(exitItem = new MenuItem("Exit"));
- // add MenuItem to Help Menu
- helpMenu.add(aboutItem = new MenuItem("About"));
- // add MenuBar to the Form
- menubar.add(fileMenu);
- menubar.add(helpMenu);
- this.setMenuBar(menubar);
-
- // --- add ActionListeners for the MenuItems ---
- // load
- loadItem.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- LoadGame();
- }
- });
- // save
- saveItem.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- SaveGame();
- }
- });
- // exit
- exitItem.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- // exit
- aboutItem.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- ShowAboutDlg();
- }
- });
-
- }
- // --- Here I define the methods called by
- // the menuItems
-
- // Save
- void SaveGame()
- {
- String SaveFileName = "Test.sav";
- FileDialog saveFileDialog1 = new java.awt.FileDialog(this, "Save",FileDialog.SAVE);
- saveFileDialog1.setFile("*.sav");
- saveFileDialog1.show();
- // SaveFileName is the name of the file returned by the dialog
- SaveFileName = saveFileDialog1.getFile();
- if (saveFileDialog1.getFile() != null) // i.e. if the File Dialog Cancel button wasn't pressed
- {
- if (!SaveFileName.endsWith(".sav"))
- displayBox.setText("Error: Wrong File type!\nBe sure to save this file with the extension: '.sav'");
- else
- displayBox.setText(Imp.SaveAdv(SaveFileName));
- }
- }
-
- // Load
- void LoadGame()
- {
- // When Load, Load is selected, display File Open dialog
- String LoadFileName = "Test.sav";
- FileDialog openFileDialog1 = new java.awt.FileDialog(this, "Load",FileDialog.LOAD);
- openFileDialog1.setFile("*.sav");
- openFileDialog1.show();
- LoadFileName = openFileDialog1.getFile();
- if (openFileDialog1.getFile() != null) // i.e. if the File Dialog Cancel button wasn't pressed
- {
- if (!LoadFileName.endsWith(".sav"))
- displayBox.setText("Error: Wrong File type!\nOnly loads files with extension: '.sav'");
- else
- displayBox.setText(Imp.LoadAdv(LoadFileName));
- }
-
- }
-
- void ShowAboutDlg()
- {
- try {
- (new AboutDlg(this)).show();
- } catch(Exception ex) {
- displayBox.setText("Can't show the About Dialog!");
- }
- }
-
-
-
- public static void main(String args[])
- {
- // You can add code anywhere in this method.
-
- try
- {
- MainForm form = new MainForm();
- form.setVisible(true);
- }
- catch(Throwable t)
- {
- System.out.println("Cannot construct the form: " + t);
- System.exit(1);
- }
- }
-
-
- public boolean mainFormWindowClosing(WindowEvent arg0)
- {
- // Put event handler code here. Return false for normal processing, true to override
-
- return false;
- }
-
- public boolean mainFormWindowClosed(WindowEvent arg0)
- {
- // Put event handler code here. Return false for normal processing, true to override
-
- return false;
- }
-
- public void stop()
- {
- // You can add code anywhere in this method.
-
- SuperCedeStop(); // Do not remove this line.
- }
-
- public void start()
- {
- // You can add code anywhere in this method.
-
- SuperCedeStart(); // Do not remove this line.
- }
-
- public void init()
- {
- // You can add code anywhere in this method.
-
- SuperCedeInit(); // Do not remove this line.
- }
-
- // -------------------------------------------------
- // ----- MY OWN HAND-WRITTEN CODE FROM HERE ON -----
- // -------------------------------------------------
-
- // The Implementor class 'wraps' up all the internal details of
- // the game itself.
- Implementer Imp = new Implementer();
- // --- The displayBox textArea
- void updatedisplayBox(String msg) {
- // !!! argument is now a String - any special message returned
- // by Adventure (e.g. "No Exit!\n")
- //
- // if msg <> "" display the message
- // display description of room anyway
- String s = msg;
- if (s.equals("")) // if no special message show room description
- { // else show message
- Room r = Imp.getAdv().getplayer().getroom();
- Vector thingshere = r.getthings();
- Vector inventory = Imp.getAdv().getplayer().getthings();
- s = "You are in " +
- r.getname() + "\n" +
- r.getdescription() + "\n" +
- "--- Things here ---\n";
- for (Enumeration e = thingshere.elements(); e.hasMoreElements(); )
- s = s + ((Thing)e.nextElement()).getname() + ", ";
- s = s + "\n--- You have ---\n";
- for (Enumeration e = inventory.elements(); e.hasMoreElements(); )
- s = s + ((Thing)e.nextElement()).getname() + ", ";
- }
- displayBox.setText( s + "\n" );
- }
-
- public void NBtnMouseClicked(MouseEvent arg0)
- {
- updatedisplayBox(Imp.getAdv().movePlayerTo(NORTH));
- }
-
- public void SBtnMouseClicked(MouseEvent arg0)
- {
- updatedisplayBox(Imp.getAdv().movePlayerTo(SOUTH));
- }
-
- public void WBtnMouseClicked(MouseEvent arg0)
- {
- updatedisplayBox(Imp.getAdv().movePlayerTo(WEST));
- }
-
- public void EBtnMouseClicked(MouseEvent arg0)
- {
- updatedisplayBox(Imp.getAdv().movePlayerTo(EAST));
- }
-
- public void takeBtnMouseClicked(MouseEvent arg0)
- {
- updatedisplayBox(Imp.getAdv().takeOb(InputTF.getText()));
- }
-
- public void dropBtnMouseClicked(MouseEvent arg0)
- {
- updatedisplayBox(Imp.getAdv().dropOb(InputTF.getText()));
- }
-
- public void lookBtnMouseClicked(MouseEvent arg0)
- {
- updatedisplayBox("");
- }
-
- // SuperCede Begin 2.0 Form Members
- // Do not remove the Begin and End markers.
- // The editor will rewrite the contents of this section each time the form is saved.
-
- // References to Beans within the Form.
-
- com.supercede.beans.stdawt.TextAreaSB displayBox;
- TextField InputTF;
- Button dropBtn;
- Button lookBtn;
- Button takeBtn;
- Button NBtn;
- Button WBtn;
- Button EBtn;
- Button SBtn;
-
- private void SuperCedeConstructor() throws IOException, ClassNotFoundException, ClassCastException, SuperCedeInvalidStateException
- {
- // Construct the actual connectors to give to our base class.
-
- Vector connectors = new Vector(9);
- connectors.addElement(new MainFormWindowClosingConnector4(this));
- connectors.addElement(new MainFormWindowClosedConnector5(this));
- connectors.addElement(new MainFormEventConnector6(this));
- connectors.addElement(new MainFormEventConnector7(this));
- connectors.addElement(new MainFormEventConnector8(this));
- connectors.addElement(new MainFormEventConnector9(this));
- connectors.addElement(new MainFormEventConnector11(this));
- connectors.addElement(new MainFormEventConnector12(this));
- connectors.addElement(new MainFormEventConnector13(this));
-
- super.initializeThis(connectors);
-
- // Make references to Beans within the Form.
-
- int i = 0;
-
- displayBox = (com.supercede.beans.stdawt.TextAreaSB) getComponent(i++);
- InputTF = (TextField) getComponent(i++);
- dropBtn = (Button) getComponent(i++);
- lookBtn = (Button) getComponent(i++);
- takeBtn = (Button) getComponent(i++);
- NBtn = (Button) getComponent(i++);
- WBtn = (Button) getComponent(i++);
- EBtn = (Button) getComponent(i++);
- SBtn = (Button) getComponent(i++);
- }
-
- private void SuperCedeInit()
- {
- }
-
- private void SuperCedeStart()
- {
- }
-
- private void SuperCedeStop()
- {
- }
-
- public MainForm() throws IOException, ClassNotFoundException, ClassCastException, SuperCedeInvalidStateException
- {
- super();
-
- mainFormPreInit();
- SuperCedeConstructor();
- mainFormPostInit();
- }
-
- public void SuperCedeWindowClosing(WindowEvent arg0)
- {
- if (mainFormWindowClosing(arg0) == false)
- {
- dispose();
- }
- }
-
- public void SuperCedeWindowClosed(WindowEvent arg0)
- {
- if (mainFormWindowClosed(arg0) == false)
- {
- System.exit(0);
- }
- }
-
- // SuperCede End 2.0 Form Members
- }
-
- // SuperCede Begin 2.0 Form Connectors
- // Do not remove the Begin and End markers.
- // The editor will rewrite the contents of this section each time the form is saved.
- // Connections for MainForm:
- // MainFormWindowClosingConnector4: from MainForm.windowClosing to MainForm.SuperCedeWindowClosing
- // MainFormWindowClosedConnector5: from MainForm.windowClosed to MainForm.SuperCedeWindowClosed
- // MainFormEventConnector6: from NBtn.mouseClicked to MainForm.NBtnMouseClicked
- // MainFormEventConnector7: from SBtn.mouseClicked to MainForm.SBtnMouseClicked
- // MainFormEventConnector8: from WBtn.mouseClicked to MainForm.WBtnMouseClicked
- // MainFormEventConnector9: from EBtn.mouseClicked to MainForm.EBtnMouseClicked
- // MainFormEventConnector11: from takeBtn.mouseClicked to MainForm.takeBtnMouseClicked
- // MainFormEventConnector12: from dropBtn.mouseClicked to MainForm.dropBtnMouseClicked
- // MainFormEventConnector13: from lookBtn.mouseClicked to MainForm.lookBtnMouseClicked
-
- final class MainFormWindowClosingConnector4 extends WindowAdapter implements SuperCedeConnector, Serializable
- {
- private MainForm target;
-
- public MainFormWindowClosingConnector4(MainForm target)
- {
- this.target = target;
- }
-
- public void windowClosing(WindowEvent arg0)
- {
- target.SuperCedeWindowClosing(arg0);
- }
- }
-
- final class MainFormWindowClosedConnector5 extends WindowAdapter implements SuperCedeConnector, Serializable
- {
- private MainForm target;
-
- public MainFormWindowClosedConnector5(MainForm target)
- {
- this.target = target;
- }
-
- public void windowClosed(WindowEvent arg0)
- {
- target.SuperCedeWindowClosed(arg0);
- }
- }
-
- final class MainFormEventConnector6 extends MouseAdapter implements SuperCedeConnector, Serializable
- {
- private MainForm target;
-
- public MainFormEventConnector6(MainForm target)
- {
- this.target = target;
- }
-
- public void mouseClicked(MouseEvent arg0)
- {
- target.NBtnMouseClicked(arg0);
- }
- }
-
- final class MainFormEventConnector7 extends MouseAdapter implements SuperCedeConnector, Serializable
- {
- private MainForm target;
-
- public MainFormEventConnector7(MainForm target)
- {
- this.target = target;
- }
-
- public void mouseClicked(MouseEvent arg0)
- {
- target.SBtnMouseClicked(arg0);
- }
- }
-
- final class MainFormEventConnector8 extends MouseAdapter implements SuperCedeConnector, Serializable
- {
- private MainForm target;
-
- public MainFormEventConnector8(MainForm target)
- {
- this.target = target;
- }
-
- public void mouseClicked(MouseEvent arg0)
- {
- target.WBtnMouseClicked(arg0);
- }
- }
-
- final class MainFormEventConnector9 extends MouseAdapter implements SuperCedeConnector, Serializable
- {
- private MainForm target;
-
- public MainFormEventConnector9(MainForm target)
- {
- this.target = target;
- }
-
- public void mouseClicked(MouseEvent arg0)
- {
- target.EBtnMouseClicked(arg0);
- }
- }
-
- final class MainFormEventConnector11 extends MouseAdapter implements SuperCedeConnector, Serializable
- {
- private MainForm target;
-
- public MainFormEventConnector11(MainForm target)
- {
- this.target = target;
- }
-
- public void mouseClicked(MouseEvent arg0)
- {
- target.takeBtnMouseClicked(arg0);
- }
- }
-
- final class MainFormEventConnector12 extends MouseAdapter implements SuperCedeConnector, Serializable
- {
- private MainForm target;
-
- public MainFormEventConnector12(MainForm target)
- {
- this.target = target;
- }
-
- public void mouseClicked(MouseEvent arg0)
- {
- target.dropBtnMouseClicked(arg0);
- }
- }
-
- final class MainFormEventConnector13 extends MouseAdapter implements SuperCedeConnector, Serializable
- {
- private MainForm target;
-
- public MainFormEventConnector13(MainForm target)
- {
- this.target = target;
- }
-
- public void mouseClicked(MouseEvent arg0)
- {
- target.lookBtnMouseClicked(arg0);
- }
- }
-
- // The following line must be the last line in the file.
- // SuperCede End 2.0 Form Connectors
-